<?php
class ModelAccountTransaction extends Model {	
	public function getTransactions($data) {
		$query = $this->db->query("SELECT crm_customer_bills_crm_customer_c.crm_customer_bills_crm_customercrm_customer_bills_idb FROM " . DB_PREFIX . "crm_customer_bills_crm_customer_c WHERE crm_customer_bills_crm_customer_c.crm_customer_bills_crm_customercrm_customer_ida ='$data'" );
            $query1 = $query->rows;
            $bill=null;
            for($i=0;$i<count($query1);$i++){
                $sql = $this->db->query("SELECT * FROM " . DB_PREFIX . "crm_customer_bills WHERE id = '".$query1[$i]['crm_customer_bills_crm_customercrm_customer_bills_idb']."'");   
                $sql1 = $sql->rows;
                $bill[$i] = $sql1[0]; 
            }
            return $bill;
	}	
					
	public function getdetailedbills($data){
            
            $query = $this->db->query("SELECT crm_customer_transactions_crm_customer_bills_c.crm_customaf9eactions_idb FROM " . DB_PREFIX . "crm_customer_transactions_crm_customer_bills_c WHERE crm_customer_transactions_crm_customer_bills_c.crm_custom19b9r_bills_ida ='".$data."'" );
            $query3 = $query->rows;  
            
            for($i=0;$i<count($query3);$i++){
                //echo "SELECT crm_customer_transactions_crm_goods_c.crm_customer_transactions_crm_goodscrm_goods_ida FROM " . DB_PREFIX . "crm_customer_transactions_crm_goods_c WHERE crm_customer_transactions_crm_goods_c.crm_customer_transactions_crm_goodscrm_customer_transactions_idb = '".$query3[$i]['crm_customaf9eactions_idb']."'";
                $sql = $this->db->query("SELECT crm_customer_transactions_crm_goods_c.crm_customer_transactions_crm_goodscrm_goods_ida FROM " . DB_PREFIX . "crm_customer_transactions_crm_goods_c WHERE crm_customer_transactions_crm_goods_c.crm_customer_transactions_crm_goodscrm_customer_transactions_idb = '".$query3[$i]['crm_customaf9eactions_idb']."'");  
                $quantity = $this->db->query("SELECT crm_customer_transactions.amount,crm_customer_transactions.quantity FROM " . DB_PREFIX . "crm_customer_transactions WHERE crm_customer_transactions.id = '".$query3[$i]['crm_customaf9eactions_idb']."'"); 
                $quantity1 = $quantity->rows;
                
                $sql1 = $sql->rows;
                //print_r($sql1);
                if($sql1[0]['crm_customer_transactions_crm_goodscrm_goods_ida'])
                {
                    //echo $sql1[0]['crm_customer_transactions_crm_goodscrm_goods_ida'];
                $sql = $this->db->query("SELECT * FROM " . DB_PREFIX . "crm_goods WHERE crm_goods.id = '".$sql1[0]['crm_customer_transactions_crm_goodscrm_goods_ida']."'"); 
                $sql3 = $sql->rows;    
                //print_r($sql3);
                $bill[$i] = array(
                 'name'     => $sql3[0]['name'],
                 'amount'   => $quantity1[0]['amount'],
                 'quantity' => $quantity1[0]['quantity'],
                );
                //echo $sql3[0]['price'];
                }
            }
            return $bill;  
        }
}
?>